home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12969 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Does C convert float to double internally ?
  5. Date: 3 Apr 1996 10:46:16 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4juh1oINNo39@keats.ugrad.cs.ubc.ca>
  8. References: <4jsllh$hkf@harbinger.cc.monash.edu.au>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4jsllh$hkf@harbinger.cc.monash.edu.au>,
  12. Biggles Cheung <bcheung@yoyo.cc.monash.edu.au> wrote:
  13.  >I was told that C compiler automatically converts "float" variable
  14.  >internally to "double" for + - * / , etc operations. Is this true?
  15.  
  16. ANSI allows the compiler to use float precision for operations between two
  17. float operands. If you want the operation to be done in a higher precision, you
  18. cast both operands to double.
  19.  
  20. float x, y, z;
  21.  
  22.     z   = (double) x / (double) y;
  23.  
  24.  >Can I force the C compiler not to do the conversion as I have an
  25.  >assignment on finding out various computing errors of different
  26.  >precisions? 
  27.  
  28. I'm not sure about this one. I'd have to check whether the standard compliant
  29. implementation _must_ use float precision. As far as I know, it is _free_ to
  30. use the smaller precision to do the operation, but is not required to.
  31.  
  32. If the implementation insists on using double precision math internally (or
  33. even something more precise---many floating point units will use extra
  34. precision) there is little you can do.
  35.  
  36.  >My advice from the lecturer is to have temporary variable of
  37.  >float to split a long equation to smaller step so that I can maximize
  38.  >the impact of single precision number on the evaluation. Is this
  39.  >feasible?
  40.  
  41. Sure, but it won't affect a particular operation like / if the compiler insists
  42. on doing it in a high precision. Converting to float  will only truncate the
  43. _result_ to a lower precision. 
  44. -- 
  45.  
  46.